package com.cndongtai.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.cndongtai.dao.BaseDao;
import com.cndongtai.dao.inter.TorchnAppUserInfoMapper;
import com.cndongtai.po.TorchnAppUserInfo;

@Repository("torchnAppUserInfoDao")
public class TorchnAppUserInfoDao extends BaseDao implements TorchnAppUserInfoMapper {

	@Override
	public int addTorchnAppUserInfo(TorchnAppUserInfo userInfo) {
		SqlSession sqlSession = getSqlSession();
		try {
			TorchnAppUserInfoMapper operation = sqlSession.getMapper(TorchnAppUserInfoMapper.class);
			return operation.addTorchnAppUserInfo(userInfo);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return 0;
	}

	@Override
	public List<TorchnAppUserInfo> queryTorchnAppUserInfoList(TorchnAppUserInfo userInfo) {
		SqlSession sqlSession = getSqlSession();
		try {
			TorchnAppUserInfoMapper operation = sqlSession.getMapper(TorchnAppUserInfoMapper.class);
			return operation.queryTorchnAppUserInfoList(userInfo);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}

	@Override
	public int activedTorchnAppUser(String userName) {
		SqlSession sqlSession = getSqlSession();
		try {
			TorchnAppUserInfoMapper operation = sqlSession.getMapper(TorchnAppUserInfoMapper.class);
			return operation.activedTorchnAppUser(userName);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return 0;
	}

	@Override
	public int modifyTorchnAppUserPassword(String userId, String password) {
		SqlSession sqlSession = getSqlSession();
		try {
			TorchnAppUserInfoMapper operation = sqlSession.getMapper(TorchnAppUserInfoMapper.class);
			return operation.modifyTorchnAppUserPassword(userId, password);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return 0;
	}

	@Override
	public TorchnAppUserInfo queryTorchnAppUserInfoByEmail(String email) {
		SqlSession sqlSession = getSqlSession();
		try {
			TorchnAppUserInfoMapper operation = sqlSession.getMapper(TorchnAppUserInfoMapper.class);
			return operation.queryTorchnAppUserInfoByEmail(email);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}

	@Override
	public TorchnAppUserInfo queryTorchnAppUserInfoById(Long userId) {
		SqlSession sqlSession = getSqlSession();
		try {
			TorchnAppUserInfoMapper operation = sqlSession.getMapper(TorchnAppUserInfoMapper.class);
			return operation.queryTorchnAppUserInfoById(userId);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}

	@Override
	public int modifyNickname(TorchnAppUserInfo userInfo) {
		SqlSession sqlSession = getSqlSession();
		try {
			TorchnAppUserInfoMapper operation = sqlSession.getMapper(TorchnAppUserInfoMapper.class);
			return operation.modifyNickname(userInfo);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return 0;
	}


	@Override
	public int modifyHeaderImage(TorchnAppUserInfo userInfo) {
		SqlSession sqlSession = getSqlSession();
		try {
			TorchnAppUserInfoMapper operation = sqlSession.getMapper(TorchnAppUserInfoMapper.class);
			return operation.modifyHeaderImage(userInfo);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return 0;
	}

	@Override
	public String queryAgreement(Integer type) {
		SqlSession sqlSession = getSqlSession();
		try {
			TorchnAppUserInfoMapper operation = sqlSession.getMapper(TorchnAppUserInfoMapper.class);
			return operation.queryAgreement(type);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return "";
	}

}
